package com.example.weiwing.home.study;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.example.weiwing.R;
import com.example.weiwing.entity.Lesson;

import java.util.List;

public class CourseSeriesAdapter extends RecyclerView.Adapter<CourseSeriesAdapter.ViewHolder> {

    private List<Lesson> lessons;


    private OnItemClickListener mOnItemClickListener;

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView seriesText;

        ViewHolder(View view) {
            super(view);
            seriesText = view.findViewById(R.id.tvSeriesNumber);
        }
    }

    public CourseSeriesAdapter(List<Lesson> seriesList) {
        lessons = seriesList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lesson_series, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        String series = lessons.get(position).getLessonName();
        holder.seriesText.setText(series);
        holder.seriesText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mOnItemClickListener.onItemClick(view, position);

            }
        });
    }
    @Override
    public int getItemCount() {
        return lessons.size();
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

}

